package cn.yunbamboos.rest.service.apidoc.helper;

import cn.yunbamboos.Model;
import cn.yunbamboos.mybatis.annotation.TableName;
import cn.yunbamboos.rest.service.anno.param.ParamType;
import cn.yunbamboos.rest.service.apidoc.meta.Schema;
import cn.yunbamboos.rest.service.apidoc.meta.schema.ObjectSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;

public class ReadComponentHelper extends ReadObjectHelper {

    private static final Logger logger = LoggerFactory.getLogger(ReadComponentHelper.class);

    private final Class<? extends Model> model;

    private Schema schema;
    private String tableName;
    private String tableCNName;

    public ReadComponentHelper(Class<? extends Model> model){
        this.model = model;
    }

    public void read() {
        ObjectSchema schema = new ObjectSchema("object");
        // 读取所有属性
        logger.info("读取Model: {}", model);
        this.readObject(schema, model);

        TableName tableName = model.getAnnotation(TableName.class);
        if(tableName != null){
            this.tableName = tableName.value();
            this.tableCNName = tableName.cn();
        }

        this.schema = schema;
    }

    public Schema getSchema() {
        return schema;
    }

    public String getTableName() {
        return tableName;
    }

    public String getTableCNName() {
        return tableCNName;
    }

    public Schema getModel(ParamType paramType, Field field){
        return null;
    }

}
